package main

import (
	"fmt"
	"os"
)

func main() {
	wd, err := os.Getwd()
	fmt.Println(wd)
	fmt.Println(err)

	fh, err := os.OpenFile("nginx-service.xml", os.O_CREATE|os.O_RDWR, 0666)
	if err != nil {
		fmt.Println(err)
	}
	defer fh.Close()
	content := []byte(fmt.Sprintf(`<service>
  <id>nginx</id>
  <name>Nginx Service</name>
  <description>High Performance Nginx Service</description>
  <logpath>%s\logs</logpath>
  <log mode="roll-by-size">
    <sizeThreshold>10240</sizeThreshold>
    <keepFiles>8</keepFiles>
  </log>
  <executable>%s\nginx.exe</executable>
  <startarguments>-p %s</startarguments>
  <stopexecutable>%s\nginx.exe</stopexecutable>
  <stoparguments>-p %s -s stop</stoparguments>
</service>`, wd, wd, wd, wd, wd))
	if _,err = fh.Write(content); err != nil {
		fmt.Print(err)
	}

	fh, err = os.OpenFile("nginx-service.exe.config", os.O_CREATE|os.O_RDWR, 0666)
	if err != nil {
		fmt.Println(err)
	}
	defer fh.Close()
	content = []byte(`<configuration>
  <startup>
    <supportedRuntime version="v2.0.50727" />
    <supportedRuntime version="v4.0" />
  </startup>
  <runtime>
    <generatePublisherEvidence enabled="false"/> 
  </runtime>
</configuration>`)
	if _,err = fh.Write(content); err != nil {
		fmt.Print(err)
	}

	fmt.Println("success")
}
